<?php
/**
 * Created by PhpStorm.
 * User: sunlight
 * Date: 2018/11/26
 * Time: 17:55
 */

namespace app\admin\controller;


class User extends BaseController{

    /**
     * 用户管理首页
     * @return mixed
     */
    public function index(){
        $data=input('param.');
        $query=http_build_query($data);

        $whereData = [];
        //转换查询调教
        if (!empty($data['start_time']) && !empty($data['end_time'])
            && $data['end_time'] > $data['start_time']){
            $whereData['create_time'] = [
                ['gt',strtotime($data['start_time'])],
                ['lt',strtotime($data['end_time'])]
            ];
        }

        //获取数据，然后填充到模板中
        $this->getPageAndSize($data);

        $m=model('User');

        //获取数据库表数据
        $user=$m->getProductByCondition($whereData, $this->from, $this->size);

        //获取满足条件的数据总数=》有多少页
        $total=$m->getProductCountByCondition($whereData);
        // 结合总数+size  =》 有多少页
        $pageTotal = ceil($total/$this->size);//1.1 =>2

        return $this->fetch('',[
            'user' => $user,
            'pageTotal' => $pageTotal,
            'curr' => $this->page,
            'start_time' => empty($data['start_time'])?'':$data['start_time'],
            'end_time' => empty($data['end_time']) ? '' : $data['end_time'],
            'query' => $query
        ]);
    }

    /**
     * 积分管理
     * @return string
     */
    public function integral(){
        return "<h1 style='color:red;font-size: 30px;'>积分管理敬请期待</h1>";
    }

    /**
     * 消费记录
     * @return string
     */
    public function records(){
        return "<h1 style='color:springgreen;font-size: 30px;'>消费记录敬请期待</h1>";
    }

}